package com.xiaoma.h5testdemo.common.models

import android.graphics.Bitmap
import com.xiaoma.h5testdemo.common.utils.BitmapUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * author: liangjingbo
 * date: 2024/4/19
 * describe:
 */
data class CollectEntity(
    val tile: String? = null,
    val url: String? = null,
    val bitStr: String? = null
) {
    @Transient
    private var bit: Bitmap? = null

    suspend fun getBitmap(): Bitmap? {
        if (bit != null) return bit
        return withContext(Dispatchers.Default) {
            bit = BitmapUtils.stringToBitmap(bitStr)
            bit
        }
    }
}